package indi.gao;

/**
 * @Description:一个类中各个模块的初始化顺序
 * @create: 2020/3/24 9:13
 * @update logs
 * @throws Exception
 */
class Thing {
    public static Bowl bowl = new Bowl(2);

    private static int b = 0;

    Thing() {
        System.out.println("父类无参构造方法");
    }

    {
        int a = 100;
        System.out.println("父类非静态代码块");
    }

    static {
        b = 100;
        System.out.println("父类静态代码块");
    }

}

class Bowl {
    public int test = 0;

    public Bowl(int maker) {
        System.out.println(maker == 1 ? "子的静态变量" : "父静态变量");
    }
}

class Table extends Thing {
    public static Bowl bowl = new Bowl(1);

    private static int b = 0;

    Table() {
        System.out.println("子无参构造方法");
    }

    {
        int a = 100;
        System.out.println("子非静态代码块");
    }

    static {
        b = 100;
        System.out.println("子静态代码块");
    }

    public static void main(String[] args) {
        System.out.println("运行main方法的时候会初始化:父静态变量->" +
                "父类静态代码块->" +
                "子的静态变量->" +
                "子静态代码块");
    }
}

public class Constructor {
    public static void main(String[] args) {
        System.out.println("new 对象的时候会 父静态变量->父静态代码块->子静态变量->子静态代码块->父非静态代码块->父构造方法->子非静态代码块->子构造方法");
        new Table();
    }

}
